use regex::Regex;

fn main() {
    println!("Hello, world!");
    let a = "On 2017-12-31, Happy. On 2018-01-01, New Year.";

    let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap();
    for caps in re.captures_iter(a) {
        println!("year: {}, month: {}, day: {}",
                 caps.get(1).unwrap().as_str(),
                 caps.get(2).unwrap().as_str(),
                 caps.get(3).unwrap().as_str());
    }

    let re = Regex::new(r"(?x)(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})").unwrap();
    let caps = re.captures(a).unwrap();
    println!("{}-{}-{}", &caps["year"], &caps["month"], &caps["day"]);
    println!("{}", re.replace_all(a, "$month/$day/$year"));
}
